package com.hup.utils.io.batch.function;

import com.hup.utils.io.batch.BaseBatch;
import com.hup.utils.io.batch.SimpleBatchResp;
import lombok.extern.log4j.Log4j2;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * 修改系统时间
 * @apiNote 需要管理员权限
 * @author hugan
 * @date 2020/1/5
 */
@Log4j2
public class ChangeTime implements BaseBatch<SimpleBatchResp> {
    private static final SimpleDateFormat DF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private final String cmd;

    public ChangeTime(Date time) {
        String[] split = DF.format(time).split(" ");
        cmd = "cmd /c time " + split[1] + "&&date " + split[0];
    }

    @Override
    public String cmd() {
        return cmd;
    }

    @Override
    public String desc() {
        return "设置时间";
    }

    @Override
    public SimpleBatchResp parse(ArrayList<String> lstResp) {
        if (!lstResp.isEmpty()) {
            //客户端没有所需的特权
            return SimpleBatchResp.fail(this, lstResp.get(0));
        }
        //成功时是没有返回消息的
        return SimpleBatchResp.success();
    }
}
